package com.chenglu.android.restaurant.shop.fragment;

import android.view.View;
import android.widget.RatingBar;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chenglu.android.R;
import com.chenglu.android.bean.TabEvent;
import com.chenglu.android.cart.bean.CartBean;
import com.chenglu.android.common.base.BaseMvpFragment;
import com.chenglu.android.common.utils.LogUtils;
import com.chenglu.android.mine.bean.CommonDataBean;
import com.chenglu.android.restaurant.adapter.ShopCategoryAdapter;
import com.chenglu.android.restaurant.adapter.ShopEvaluateAdapter;
import com.chenglu.android.restaurant.bean.CurrentShopsInfoBean;
import com.chenglu.android.restaurant.bean.GoodscategorylisBean;
import com.chenglu.android.restaurant.bean.ReviewTypeCountBean;
import com.chenglu.android.restaurant.bean.ShopReviewPageBean;
import com.chenglu.android.restaurant.event.ReviewTypeCountEvent;
import com.chenglu.android.restaurant.mvp.contract.RestaurantShopContract;
import com.chenglu.android.restaurant.mvp.presenter.RestaurantShopPresenter;
import com.chenglu.android.restaurant.shop.details.ShopDetailsActivity;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class EvaluateFragment extends BaseMvpFragment<RestaurantShopPresenter> implements RestaurantShopContract.View {
    @BindView(R.id.tv_shop_score)
    TextView tvShopScore;
    @BindView(R.id.tv_shop_ztpf)
    TextView tvShopZtpf;
    @BindView(R.id.ratingBar_shop_score)
    RatingBar ratingBarShopScore;
    @BindView(R.id.tv_shop_allcount)
    TextView tvShopAllcount;
    @BindView(R.id.tv_shop_lowscorecount)
    TextView tvShopLowscorecount;
    @BindView(R.id.tv_shop_piccount)
    TextView tvShopPiccount;
    @BindView(R.id.rv_shop_pj)
    RecyclerView rvShopPj;
    private ShopDetailsActivity activity;

    ArrayList<ShopReviewPageBean.DataBean.RecordsBean> recordsBeans = new ArrayList<>();
    private ShopEvaluateAdapter shopEvaluateAdapter;

    public static Fragment getInstance(ShopDetailsActivity shopDetailsActivity) {
        EvaluateFragment evaluateFragment = new EvaluateFragment();
        evaluateFragment.activity = shopDetailsActivity;
        return evaluateFragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_store_details_evaluate;
    }

    @Override
    protected void initView() {
        mPresenter = new RestaurantShopPresenter();
        mPresenter.attachView(this);
        mPresenter.getShopReviewPage(activity.tenantId, 1, 10, 0, 0);

        shopEvaluateAdapter = new ShopEvaluateAdapter(mContext,recordsBeans );
        rvShopPj.setLayoutManager(new LinearLayoutManager(mContext));
        rvShopPj.setAdapter(shopEvaluateAdapter);

    }

    @Override
    protected boolean registerEventBus() {
        return true;
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventBus(ReviewTypeCountEvent event) {
//        LogUtils.e("ReviewTypeCountEvent" + activity.reviewTypeCountBean.getData().getAllCount());
        switch (event.getType()) {
            case 1:
                tvShopScore.setText(activity.currentShopsInfoBean.getData().getScore() + "");
                ratingBarShopScore.setRating(activity.currentShopsInfoBean.getData().getScore());
                break;
            case 2:
                tvShopAllcount.setText("全部评价" + activity.reviewTypeCountBean.getData().getAllCount());
                tvShopLowscorecount.setText("低分评价" + activity.reviewTypeCountBean.getData().getLowScoreCount());
                tvShopPiccount.setText("晒图评价" + activity.reviewTypeCountBean.getData().getPicCount());
                break;
        }


    }


    @Override
    public void getCurrentShopsInfo(CurrentShopsInfoBean bean) {

    }

    @Override
    public void getGoodscategoryList(GoodscategorylisBean bean) {

    }

    @Override
    public void getReviewTypeCount(ReviewTypeCountBean bean) {

    }

    @Override
    public void getShopReviewPage(ShopReviewPageBean bean) {
        recordsBeans.addAll(bean.getData().getRecords());
        shopEvaluateAdapter.notifyDataSetChanged();
    }

    @Override
    public void getAddCartShop(CommonDataBean bean) {

    }

    @Override
    public void getShopsCartList(CartBean bean) {

    }

    @Override
    public void getShopCouponreceive(CommonDataBean bean) {

    }

    @OnClick({R.id.tv_shop_allcount, R.id.tv_shop_lowscorecount, R.id.tv_shop_piccount})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_shop_allcount:
                break;
            case R.id.tv_shop_lowscorecount:
                break;
            case R.id.tv_shop_piccount:
                break;
        }
    }
}
